<template>
  <div class="dashboard-container">
    <div @click="$router.go(-1)">
      <i class="el-icon-back"></i>
      <span>返回</span>
    </div>
    <el-table
      :data="
        tableData.slice(
          (form.pageNo - 1) * form.pageSize,
          form.pageNo * form.pageSize
        )
      "
      border
    >
      <el-table-column prop="id" label="ID" align="center"> </el-table-column>
      <el-table-column prop="title" label="名称" align="center"></el-table-column>
      <el-table-column prop="state" label="增加 or 减少" align="center">
        <template slot-scope="{ row }">
          <el-tag :type="row.state == 1 ? 'primary' : 'success'">{{
              row.state | vipfilter
            }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="price" label="金额" align="center"></el-table-column>
      <el-table-column prop="addtime" label="时间" align="center">
        <template slot-scope="scope">
          {{ scope.row.addtime | datefilter }}
        </template>
      </el-table-column>

    </el-table>
    <Pagination
      :currentPage="this.form.pageNo"
      :size="this.form.pageSize"
      :total="total"
      @changelimit="changelimit"
      @changecurrentPage="changecurrentPage"
    ></Pagination>
  </div>
</template>

<script>
import { getmarketlist } from '@/api/market'
export default {
  name: "Dashboard",
  components: {
  },
  data() {
    return {
      form: {
        pageNo: 1,
        pageSize: 15,
        adminid:Number(localStorage.getItem('userId'))
      },
      total: 0,
      tableData: [],
    };
  },
  filters: {
    vipfilter(val) {
      if (val == 1) {
        return "增加";
      } else if (val == 2) {
        return "减少";
      }
    },
    datefilter(val) {
      if (val) {
        var date = new Date(parseInt(val) * 1000);
        var Year = date.getFullYear();
        var Moth =
          date.getMonth() + 1 < 10
            ? "0" + (date.getMonth() + 1)
            : date.getMonth() + 1;
        var Day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        var Hour =
          date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var Minute =
          date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
        var Sechond =
          date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
        var GMT =
          Year +
          "-" +
          Moth +
          "-" +
          Day +
          "   " +
          Hour +
          ":" +
          Minute +
          ":" +
          Sechond;

        return GMT;
      } else {
        return "";
      }
    },
  },
  methods: {
    getSimpleText(html) {
      var re1 = new RegExp("<.+?>", "g"); //匹配html标签的正则表达式，"g"是搜索匹配多个符合的内容
      var msg = html.replace(re1, ""); //执行替换成空字符
      return msg;
    },
    // 子传父:自定义事件
    refresh() {
      this.getcouponlist1();
    },
    async getcouponlist1() {
      let result = await getmarketlist(this.form);
      // let result = await getmarketlist({
      //   uid: this.form.uid,
      //   pageNo: this.form.pageNo,
      //   pageSize: this.form.pageSize,
      // });
      console.log(result);
      if (result.code == 0) {
        if (result.data.data != []) {
          this.tableData = result.data.data;
          this.total = result.data.length;
        }
      }
    },
    changelimit(val) {
      this.form.pageSize = val;
      this.getcouponlist1();
    },
    changecurrentPage(val) {
      this.form.pageNo = val;
      this.getcouponlist1();
    },
  },
  watch: {
    "form.uid": {
      handler(newVal) {
        if (newVal == "") {
          this.getcouponlist1();
        }
      },
    },
  },
  mounted() {
    this.getcouponlist1();
  },

  created() {
    this.$nextTick(() => {
      this.form.uid = Number(this.$route.query.uid);
    });
  },

};
</script>

<style lang="scss" scoped>
.dashboard {
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
</style>
